package com.common.security.errors;

import com.common.security.abstracts.AbstractError;

/**
 * Error code range: 61 - 80
 * 
 * @author Ady
 *
 */
public class SessionError extends AbstractError {

	public static final int NO_SESSION_PROVIDED = 61;
	private static final String MESSAGE_NO_SESSION_PROVIDED = "The session was not provided";
	private static final String CAUSE_NO_SESSION_PROVIDED = "The session is missing from the request";
	private static final String DESCRIPTION_NO_SESSION_PROVIDED = "Relog to create a new session";
	
	public static final int SESSION_NOT_FOUND = 62;
	private static final String MESSAGE_SESSION_NOT_FOUND = "The session does not exist";
	private static final String CAUSE_SESSION_NOT_FOUND = "The session may have been destroyed or was idle for too long";
	private static final String DESCRIPTION_SESSION_NOT_FOUND = "Relog to recreate a new session";
	
	public static final int UNAUTHORIZED_USER = 63;
	private static final String MESSAGE_UNAUTHORIZED_USER = "The user is not authorized to execute this action";
	private static final String CAUSE_UNAUTHORIZED_USER = "The user does not have the required rights to execute this action";
	private static final String DESCRIPTION_UNAUTHORIZED_USER = "Ask for authorization or an authorized user to execute this action";
	
	public static final int MISSING_USER_TYPE = 64;
	private static final String MESSAGE_MISSING_USER_TYPE = "The user type is missing for this user";
	private static final String CAUSE_MISSING_USER_TYPE = "This user has no user type";
	private static final String DESCRIPTION_MISSING_USER_TYPE = "The user will be considered unauthorized for this action";
	
	public SessionError(int code) {
		super(code);
		
		switch(code) {
			case NO_SESSION_PROVIDED: {
				setMessage(MESSAGE_NO_SESSION_PROVIDED);
				setCause(CAUSE_NO_SESSION_PROVIDED);
				setDescription(DESCRIPTION_NO_SESSION_PROVIDED);
				break;
			}
			case SESSION_NOT_FOUND: {
				setMessage(MESSAGE_SESSION_NOT_FOUND);
				setCause(CAUSE_SESSION_NOT_FOUND);
				setDescription(DESCRIPTION_SESSION_NOT_FOUND);
				break;
			}
			case UNAUTHORIZED_USER: {
				setMessage(MESSAGE_UNAUTHORIZED_USER);
				setCause(CAUSE_UNAUTHORIZED_USER);
				setDescription(DESCRIPTION_UNAUTHORIZED_USER);
				break;
			}
			case MISSING_USER_TYPE: {
				setMessage(MESSAGE_MISSING_USER_TYPE);
				setCause(CAUSE_MISSING_USER_TYPE);
				setDescription(DESCRIPTION_MISSING_USER_TYPE);
				break;
			}
		}
	}
}
